package com.lpb.spring.lpbspring.getway.model;

public class Response {
    private String code;
    private String msg;
    private Integer flag;
    private Object data;
    private String describe;
    private Boolean success;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getFlag() {
        return flag;
    }

    public void setFlag(Integer flag) {
        this.flag = flag;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public RestModel get(){
        RestModel model = new RestModel();
        model.setSuccess(this.success);
        model.setData(data);
        model.setCode(this.code);
        model.setDescribe(this.describe);
        return model;
    }

    public RestModel asModel() {
        if ("SUCCEED".equals(this.code) || "1".equals(String.valueOf(flag))) {
            return Success.success(data);
        } else {
            Fail fail = new Fail();
            fail.setDescribe(msg);
            fail.setCode("ERROR");
            return fail;
        }
    }
}
